package com.CampusLife.controller;
import	java.io.IOException;
import java.util.List;

import com.CampusLife.bean.Picture;
import com.CampusLife.service.IPictureService;
import com.CampusLife.until.ImagesUpload;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@Controller
@RequestMapping("/picture")
public class PictureController {
@Resource
    private IPictureService iPictureService;
@RequestMapping("/jumpUpdatePictureEdit")
public  String jumpUpdateUserEdit(int id,Model model){
    Picture picture=iPictureService.ById(id);
     model.addAttribute("picture",picture);
     return  "admin/updatelunbo";
    }
@RequestMapping("/update")
    public  String update(Integer id,@RequestParam("file") MultipartFile file)throws Exception {
        ImagesUpload imagesUpload =new ImagesUpload();
        String photo=  imagesUpload.Upload(file);
        Picture picture=new Picture();
        picture.setId(id);
        picture.setPicture(photo);
        iPictureService.update(picture);
        return "redirect:/picture/getindex";
    }
    @RequestMapping("/getindex")
    public  String getindex(Model model){
   List<Picture> pictures =iPictureService.getIndex();
   model.addAttribute("pictures",pictures);
   return "admin/lunbotu1";
    }
    @RequestMapping("/getShop")
    public  String getShop(Model model){
        List<Picture> pictures =iPictureService.getShop();
        model.addAttribute("pictures",pictures);
        return "admin/lunbotu2";
    }
}
